<script setup lang="ts">
import {useStore} from "@/stores";
import {useRouter} from "vue-router";

import {StatusCode} from "@/api";

const store = useStore();
const router = useRouter();

router.isReady().then(async () => {
  try {
    if(router.currentRoute.value.path === '/login') return;

    if(store.user.token === null || (await store.user.myInfo()).data.code !== StatusCode.SUCCESS) {
      router.push('/login');
      return;
    }

    if(router.currentRoute.value.path === '/') router.push('/home');
  } catch (e) {
    router.push('/login');
  }
});



</script>

<template>
  <router-view />
</template>

<style>
body {
  margin: 0;
}
</style>
